<?php
class NoticeAction extends SystemCommonAction {
    public function showList() {
        $Notice = D("Notice");
        $notice_info = $Notice->where()->order('add_time desc')->limit('0,12')->select();
        $this->assign('notice_info',$notice_info);
        $this->display('index');
    }
    public function showAdd() {
        $id = intval($_GET['id']);
        if($id>0) {
            $Notice = D("Notice");
            $notice_info = $Notice->where('id = '.$id)->find();
            if(count($notice_info)>0) {
                $this->assign('notice',$notice_info);
            }
        }
        $this->display('showAdd');
    }
    public function add() {
        $id = intval($_POST['id']);
        $arr = array();
        $arr['title'] = $_POST['title'];
        $arr['type'] = $_POST['type'];
        $arr['content'] = htmlspecialchars($_POST['content']);
        $arr['add_time'] = time();
        $Notice = D("Notice");
        if($id>0) {
            $notice_info = $Notice->where('id = '.$id)->find();
            if(count($notice_info)>0) {
                $rs = $Notice -> where('id = '.$id) ->save($arr);
                if($rs) {
                    $this->assign('jumpUrl',__APP__.'/Admin/Notice/showList');
                    $this->success('修改成功！');
                }else {
                    $this->assign('jumpUrl',__APP__.'/Admin/Notice/showList');
                    $this->success('修改失败！');
                }
                return true;
            }
        }
        if($Notice->add($arr)) {
            $this->assign('jumpUrl',__APP__.'/Admin/Notice/showList');
            $this->success('成功！');
        }
        else {
            $this->assign('jumpUrl',__APP__.'/Admin/Notice/showList');
            $this->success('失败！');
        }


    }

    public function del() {
        $id = intval($_GET['id']);
        if($id>0) {
            $Notice = D("Notice");
            $notice_info = $Notice->where('id = '.$id)->find();
            if(count($notice_info)>0) {
                if($Notice->where('id = '.$id)->delete()) {
                    $this->assign('jumpUrl',__APP__.'/Admin/Notice/showList');
                    $this->success('成功！');
                }
            }
        }
        $this->assign('jumpUrl',__APP__.'/Admin/Notice/showList');
        $this->success('失败！');
    }
}

?>
